Kits.list   B
last analyzed

Complexity

Conditions 2
Paths 5

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
nc 5
nop 1
dl 0
loc 28
rs 8.8571
c 2
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A 0 20 3
1
const util = require('../util')
2
3
const Kits = {
4
  cache: []
5
}
6
7
Kits.list = function (callback) {
8
  if (Kits.cache.length) {
9
    callback(Kits.cache)
10
    return
11
  }
12
13
  var stopSpinner = util.output.wait('Loading available starter kits')
14
  util.request('kits/short').end(function (response) {
15
    if (response.error || !response.body) {
16
      stopSpinner(response.error)
17
      process.exit()
18
    }
19
20
    stopSpinner()
21
    var list = response.body.data.sort(function (a, b) {
22
      if (a === 'basic') {
23
        return -1
24
      }
25
      if (b === 'basic') {
26
        return 1
27
      }
28
      return a > b ? 1 : -1
29
    })
30
31
    Kits.cache = list
32
    callback(list)
33
  })
34
}
35
36
module.exports = Kits
37